<template>
	<view class="content">
		<u-navbar :autoBack="true" :placeholder="true" bgColor="rgba(0, 0, 0, 0.0)">
			<view class="u-nav-slot" slot="left">
				<u-icon name="arrow-left" color="#fff" size="24"></u-icon>
			</view>
			<view class="u-nav-slot" slot="center">
				<view class="nav-text">
					更换头像框
				</view>
			</view>
		</u-navbar>
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="head-box" :style="{ backgroundImage: `url(${'https://m.lqvvvv.com' + item.image})` }">
				</view>
				<view v-if="item.is_use == 0" class="btn1" @click="goplay(item.avatar_id)">使用</view>
				<view v-else class="btn2">使用中</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			goplay(id) {
				let app = this
				uni.showLoading({
					mask:true
				})
				let params = {
					avatar_id: id
				}
				app.$Request({
					method: 'POST',
					url: '/api/avatar/useAvatar',
					data: params,
					ismsg: true,
				}).then(res => {
					console.log(res)
					uni.hideLoading()
					if (res.code == 1) {
						app.getList()
					}
				})
			},

			getList() {
				let params = {
					page: 1,
					limit: 100
				}
				this.$Request({
					method: 'POST',
					url: '/api/Avatar/getMyAvatar',
					data: params,
					ismsg: false,
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						this.list = res.data.data
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #F7F8FC;
	}
</style>
<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background-image: url('https://m.lqvvvv.com/assets/static/index/nav-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 900rpx;
		padding: 30rpx;

		.nav-text {
			font-size: 36rpx;
			font-weight: bold;
			color: #fff;
		}

		.list {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.item {
				width: 30%;
				padding: 20rpx 30rpx;
				background-color: #fff;
				border-radius: 30rpx;
				text-align: center;
				margin-top: 30rpx;

				.head-box {
					width: 130rpx;
					height: 130rpx;
					background-repeat: no-repeat;
					background-size: 100% 100%;
					margin: 0 auto;
				}

				.integral {
					color: #F24789;
					margin-top: 20rpx;
					font-size: 24rpx;
				}

				.btn1 {
					width: 112rpx;
					height: 48rpx;
					line-height: 48rpx;
					color: #fff;
					border-radius: 50px;
					text-align: center;
					margin: 0 auto;
					margin-top: 20rpx;
					font-size: 26rpx;
					background: linear-gradient(90deg, #C58AF0 0%, #6272ED 100%);
				}

				.btn2 {
					width: 112rpx;
					height: 48rpx;
					line-height: 48rpx;
					color: #fff;
					border-radius: 50px;
					text-align: center;
					margin: 0 auto;
					margin-top: 20rpx;
					font-size: 26rpx;
					background: linear-gradient(90deg, #c2c2c2 0%, #c2c2c2 100%);
				}

				.exchange {
					width: 130rpx;
					height: 60rpx;
					margin-top: 10rpx;
				}
			}
		}

	}
</style>